#!/bin/bash
docker_name=mysql
data_dir="/usr/local/backup"
docker exec -i $docker_name mysqldump --skip-opt -uroot -pwhmysql123 --default-character-set=utf8 TEST > "$data_dir/TEST_`date +%Y%m%d%H%M%S`.sql"
docker exec -i $docker_name mysqldump --skip-opt -uroot -pwhmysql123 --default-character-set=utf8 code_generator > "$data_dir/code_generator_`date +%Y%m%d%H%M%S`.sql"
docker exec -i $docker_name mysqldump --skip-opt -uroot -pwhmysql123 --default-character-set=utf8 PRE_220323 > "$data_dir/PRE_`date +%Y%m%d%H%M%S`.sql"
# 删除7天以前的备份
find $data_dir -mtime +7 -name 'TEST_*.sql' -exec rm -rf {} \;
find $data_dir -mtime +7 -name 'code_generator_*.sql' -exec rm -rf {} \;
find $data_dir -mtime +7 -name 'PRE_*.sql' -exec rm -rf {} \;
